(function(window){
	var getToken=function(){
		if(1==1){
			return "";
		}
		var userInfo = JFTApp.getUser();
		var params = [];
		params.push("APP_TAG=1");
		if(userInfo && userInfo["APP_ID"]){
			params.push("APP_ID="+userInfo["APP_ID"]);
			params.push("APP_NO="+userInfo["APP_NO"]);
			params.push("APP_TOKEN="+userInfo["APP_TOKEN"]);
		}
		return params.join("&");
	};
	var customFunc={
//		SITE_URL:"http://127.0.0.1:8080/MallWeb",
//		RES_URL:"http://127.0.0.1:8080/MallWeb",
		SITE_URL:"http://"+window.location.host,
		//RES_URL:"http://upload.huicentury.com",
		WEXIN_JS:"http://res.wx.qq.com/open/js/jweixin-1.0.0.js",
		SHARE_USER:"SHARE_USER",		//分享用户
		USER_KEY : "userNo",
		PAGE_DETAIL : "PAGE_DETAIL",
		_getAjaxParam:function(param){
			var inParams = null;
			var token = getToken();
			if(token && !JFT.isBlank(token)){
				inParams = token;
				if(param){
					if(typeof(param)=="string"){
						inParams += "&"+param;
					}else{
						for(var k in param){
							inParams += "&"+k+"="+param[k];
						}
					}
				}
			}else{
				var returnUrl = encodeURIComponent(location.href);
				if(param){
					if(typeof(param)=="string"){
						param += "&returnUrl="+returnUrl;
					}else{
						param["returnUrl"]=location.href;
					}
				}else{
					param = "&returnUrl="+returnUrl;
				}
				inParams = param;
			}
			return inParams;
		},
		ajaxPost:function(url, param, success){
			if(arguments.length==2 || !success){
				success = param;
				param = null;
			}
			JFT.ajaxJsonp(SITE_URL+"/"+url, _getAjaxParam(param), success);
		},
		ajaxGet:function(url, param, success){
			ajaxPost(url, param, success);
		},
		getShareUser:function(){
			var userNo = JFT.session.get(SHARE_USER);
			return userNo && !JFT.isBlank(userNo)? userNo : "";
		}
	};
	for(var property in customFunc){
		window[property] = customFunc[property];
	}
	window.UrlLib={
		index: SITE_URL+"/index",
		topicList: SITE_URL+"/list/topic",
		payResult: SITE_URL+"/orderPay/payResult",
		search: SITE_URL+"/search",
		orderPay: SITE_URL+"/orderPay/pay",
		orderCheck: SITE_URL+"/orderCheck",
		cart: SITE_URL+"/cart",
		luckyCart: SITE_URL+"/lucky/cart",
		luckyPay: SITE_URL+"/orderPay/luckyPay",
		luckyIndex: SITE_URL+"/lucky",
		luckyPayResult: SITE_URL+"/orderPay/luckyPayResult",
	    login:SITE_URL+"/passport",
	    forgetNext:SITE_URL+"/passport/finish",
	    order:SITE_URL+"/myorder",
	    refund: SITE_URL+"/refund",
	    refundMulti:SITE_URL+"/refund/refundMulti",
	    refundNext:SITE_URL+"/refund/next",
	    userinfo: SITE_URL+"/user",
	    bindphone:SITE_URL+"/bindphone",
	    modifyPhone: SITE_URL+"/bindphone/modifyPhone",
	    detail:SITE_URL+"/detail",
	    uploadPspt:SITE_URL+"/pspt/uploadFile",
	    news: SITE_URL+"/news",
	    member:SITE_URL+"/user"
	};
	//类别缓存键值
	var CATE_DATA = "CATE_DATA";
	var common={
		//统计购物车商品
		statCart:function(){
			ajaxGet("index/statCart", function(data){
				var cartNum = data["resultData"];
				$("#cartStat").html(cartNum);
				if(cartNum && cartNum!="0"){
					$("#cartStat").show();
				}else{
					$("#cartStat").hide();
				}
			});
		},
		//菜单项事件
		bindMenuItemEvent:function(mibEL){
			$("#"+mibEL+" .dot").touch(function(){
				$(this).addClass("current");
				$(this).next(".slide_down").show();
				$(this).parent().find(".full_mark").show();
			});
			$("#"+mibEL+" .full_mark").touch(function(){
				var parentEl = $(this).parent();
				parentEl.find(".dot").removeClass("current");
				parentEl.find(".slide_down").hide();
				$(this).hide();
			});
		},
		// 置顶
		toTopEvent:function(){
			if(!$(".common_main") || !$(".common_main").length) return;
			$(".common_main").scroll(function(){
				if($(".common_main").scrollTop()>200){
					if(!$("#toTop").is(":visible")){
						$("#toTop").stop(true,true).fadeIn();
					}
				}else{
					$("#toTop").stop(true,true).fadeOut();
				}
			});
			$("#toTop").touch(function(){
				$(".common_main").animate({scrollTop:0},500);
			});
		}
	};
	window.JFTBusi = common;
})(window);

$(function(){
	if($("#cartStat") && $("#cartStat").length){
		JFTBusi.statCart();
	}
	if($("#menuItemBtn") && $("#menuItemBtn").length){
		JFTBusi.bindMenuItemEvent("menuItemBtn");
	}
//	if (!JFTApp.enable) {
		JFT.session.put(SHARE_USER, JFT.getUrlParam(USER_KEY));
//	}
	//绑定置顶事件
	JFTBusi.toTopEvent();
});